package jys.test.yddata.ui;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class DrawNonnView extends View {
    private int arc_red = Color.parseColor("#f26522");
    private int progress = 0;

    public DrawNonnView(Context context) {
        super(context);
    }

    public DrawNonnView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DrawNonnView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    @SuppressLint("DrawAllocation")
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        int speed = 20;
        progress+=speed;

        Paint paint = new Paint();
        //设置画笔颜色
        paint.setColor(arc_red);
        //设置圆弧的宽度
        paint.setStrokeWidth(30);
        //设置圆弧为空心
        paint.setStyle(Paint.Style.STROKE);
        //消除锯齿
        paint.setAntiAlias(true);

        int bigger = 3;
        int smoker = (progress%500)-250;
        smoker = smoker>0?smoker:-smoker;

        int ctr = getWidth() / 2;
        int rds = ctr - 30 - smoker/bigger;
        int lin = getWidth() / 4 - smoker/bigger;

        //根据进度画圆环
        canvas.drawCircle(ctr, ctr, rds, paint);

        //画线
        canvas.drawLine(ctr-lin, ctr-lin, ctr+lin, ctr+lin, paint);
        canvas.drawLine(ctr-lin, ctr+lin, ctr+lin, ctr-lin, paint);

        //每隔10毫秒界面刷新
        postInvalidateDelayed(10);

        if (progress > 1000) {
            progress = 0;
            setVisibility(View.GONE);
        }
    }
}
